if (requestbody.content) {
    var args = [];
    var jsonData = jsonUtils.toObject(requestbody.content);
    var workflowDefinition = null, documentType = null, templateId = null;

    if (jsonData.workflow) {workflowDefinition = jsonData.workflow; }
    if (jsonData.docType) {documentType = jsonData.docType; }
    if (jsonData.tmpId) {templateId = jsonData.tmpId; }

    if (workflowDefinition == "activiti$vacAppealSimple") {
        if (documentType == "order") {
            if (templateId != null) {
                generateOrderPerDocPreview(templateId);
            } else returnStatus(400, "Workflow data has not been provided(3).", true);
        } else generateVacAppealDocPreview();
    } else returnStatus(400, "Workflow data has not been provided(3).", true);

} else returnStatus(400, "Workflow data has not been provided(2).", true);

function generateOrderPerDocPreview() {
    var orderPer = "";
    jsonData = jsonUtils.toObject(requestbody.content);
    args = jsonData; //getOrderPerData();

    // get nextAssignee fullName
    if (jsonData.assoc_rccwf_nextAssignee_added) {
        var nextAssignee = search.findNode(jsonData.assoc_rccwf_nextAssignee_added);
        jsonData.assigneeName = nextAssignee.properties.firstName + " " + nextAssignee.properties.lastName;
    } else jsonData.assigneeName = null;

    var template = companyhome.childByNamePath("/Data Dictionary/Presentation Templates/previewTemplates/vacAppealSimple/" + templateId + "-order.ftl");

    if (template != null && template != undefined) {
        var outputFile = userhome.createFile("orderPerSimplePreview.html");
        orderPer = outputFile.processTemplate(template, args);
        outputFile.addAspect("sys:temporary");
        outputFile.remove();
        model.result = orderPer;
    } else returnStatus(500, "Document template not found.", true);

}

function generateVacAppealDocPreview() {
    var vacAppeal = "", template = null, outputFile = null;
    //jsonData = jsonUtils.toObject(requestbody.content);
    args = jsonData; //getVacAppealData();
    args.appealDate = getAppealDate();

    if (args.prop_rccwf_wfTitle != null) {
        template = companyhome.childByNamePath("/Data Dictionary/Presentation Templates/previewTemplates/vacAppealSimple/" + args.prop_rccwf_wfTitle + ".ftl");
    } else returnStatus(500, "Document title undefined.", true);

    if (template != null && template != undefined) {
        outputFile = userhome.createFile("vacAppealSimplePreview.html");
        vacAppeal = outputFile.processTemplate(template, args);
        outputFile.addAspect("sys:temporary");
        outputFile.remove();
        model.result = vacAppeal;
    } else returnStatus(500, "Document template not found.", true);
}


function getAppealDate(){
    var appealDate;
    var date = new Date(),
        day = date.getDate().toString(),
        month = getMonth(date.getMonth()),
        year = date.getFullYear().toString();

    if (day.length == 1) {
        day = "0" + day;
    }
    if (month.length == 1) {
        month = "0"+month;
    }
    appealDate = year + "-" + month + "-" + day;
    return appealDate;
}

function getMonth(month) {
    var menuo = "";
    switch (month){
        case 0: menuo="01"; break;
        case 1: menuo="02"; break;
        case 2: menuo="03"; break;
        case 3: menuo="04"; break;
        case 4: menuo="05"; break;
        case 5: menuo="06"; break;
        case 6: menuo="07"; break;
        case 7: menuo="08"; break;
        case 8: menuo="09"; break;
        case 9: menuo="10"; break;
        case 10: menuo="11"; break;
        case 11: menuo="12"; break;
    }
    return menuo;
}

function returnStatus(code, message, redirect) {
    status.code = code;
    status.message = message;
    status.redirect = redirect;
}

